import Ember from 'ember';
import BaseBusiness from '../base-business';
export default BaseBusiness.extend({
    dateService: Ember.inject.service("date-service"),
    global_curStatus: Ember.inject.service("current-status"),
    queryParams: {
        id: {
            refreshModel: true
        },
        editMode: {
            refreshModel: true
        },
    },
    detailEdit: true,
    header_title: '绩效详情',
    model() {
        return {};
    },
    setupController(controller, model) {
        this._super(controller, model);
        controller.set("showEditBut",true);
        var editMode = this.getCurrentController().get('editMode');
        var id = this.getCurrentController().get('id');
        //查询所有的员工信息
        let params = {};
        let filter = {};
        filter = $.extend({}, filter, {
            '[staffStatus][typecode@$like]@$or1---1': 'staffStatusIn'
        });
        filter = $.extend({}, filter, {
            '[staffStatus][typecode@$like]@$or1---2': 'staffStatusTry'
        });
        params.filter = filter;
        this.store.query('employee', params).then(function(employeeList) {
            employeeList.forEach(function(employee) {
                employee.set('sortName', pinyinUtil.getFirstLetter(employee.get("name")));
            });
            controller.set('employeeList', employeeList);
        });
        let user = this.get("global_curStatus").getUser();
        controller.set('curUser',user);
        // this.store.query('salaryposition', {}).then(function(salarypositionList) {
        //     controller.set('salarypositionList', salarypositionList);
        // });
        controller.set("performanceType", null);
        controller.set("curPerformanceItem", null);
        controller.set("curPerformanceDetial", null);
        if(editMode == 'edit'){
          let employeeproformancessInfo = this.store.peekRecord('employeeproformance',id);
          controller.set('employeeproformancessInfo',employeeproformancessInfo);
          controller.set('detailEdit',false);
          let createTime = employeeproformancessInfo.get("createTime");
          //获取完整的日期
          var date=new Date();
          var year=date.getFullYear();
          var month=date.getMonth()+1;
          month =(month<10 ? "0"+month:month);
          let beginCreateTime = this.get("dateService").getFirstSecondStampOfMonth(year,month);
          if(createTime < beginCreateTime) {
            controller.set("showEditBut",false);
          }
          controller.set("salaryPositionName",employeeproformancessInfo.get("salaryPosition.name"));
          controller.set("salaryPositionObj",employeeproformancessInfo.get("salaryPosition"));
          controller.set("showFormanceType", true);
          controller.set("showPerformanceItem", true);
          controller.set("showPerformanceDetial", true);
        }else if(editMode == 'add'){
          let employeeproformancessInfo = this.store.createRecord('employeeproformance',{});
          controller.set('employeeproformancessInfo',employeeproformancessInfo);
          controller.employeeproformancesModelObs();
          controller.set('detailEdit',true);
          controller.set("showFormanceType", false);
          controller.set("showPerformanceItem", false);
          controller.set("showPerformanceDetial", false);
        }
    }
});
